<template>
  <div class="common" >
    <div class="action">
      <el-button type="primary" @click="back">返回</el-button>
    </div>
<!--    <div class="line"></div>-->
    <div class="info" >
      <div style="display: flex;padding-top: 15px;margin-top: 20px;">
        <el-form-item label="模板名称：" style="margin-right: 30px" required >
          <!-- <el-select class="selectStyle" @change="showForm" v-model="formData.model" placeholder="请选择安全档案模板">
            <el-option>外部单位模板一</el-option>
          </el-select> -->
          <el-input v-model="modelName" style="width: 250px" placeholder="" clearable readonly/>
        </el-form-item>
        <el-form-item label="单位类型" required>
<!--          <el-select class="selectStyle" placeholder="自动填充模板关联的外部单位类型" v-model="unitType" >-->
<!--            <el-option-->
<!--              v-for="item in unitTypeList"-->
<!--              :key="item.id"-->
<!--              :label="item.catalogueName"-->
<!--              :value="item.id"-->
<!--              readonly-->
<!--            />-->
<!--          </el-select>-->
          <el-input v-model="unitType" style="width: 250px" placeholder="" clearable readonly/>
        </el-form-item>
      </div>
      <!-- <div style="border-top: 1px solid var(--el-border-color);margin-bottom: 5px;"></div> -->
      <!-- <div> -->
         <!-- <el-form v-show="formVisible" label-width="120px"> -->
        <!-- <el-form>
            <div class="rowData">
              <el-form-item label="单位编号：" class="inputStyle">
                <el-input v-model="formData.unitNumber"></el-input>
              </el-form-item>
              <el-form-item label="单位名称：" class="inputStyle">
                <el-input v-model="formData.unitName"></el-input>
              </el-form-item>
              <el-form-item label="驻场房间编号：" class="inputStyle">
                <el-input v-model="formData.roomNumber"></el-input>
              </el-form-item>
            </div>
            <div style="margin: 20px 30px 0 30px;">
              <el-form-item label="业务简述：">
                <el-input v-model="formData.businessDesc"></el-input>
              </el-form-item>
            </div>
            <div class="rowData">
              <el-form-item label="合同期限：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
              <el-form-item label="负责人电话：" class="inputStyle">
                <el-input v-model="formData.principalPhone"></el-input>
              </el-form-item>
              <div class="inputStyle">
                <el-text>是否签订安全协议：</el-text>
                <el-radio-group v-model="formData.isSign">
                  <el-radio label="0">是</el-radio>
                  <el-radio label="1">否</el-radio>
                </el-radio-group>
              </div>
            </div>
            <div class="rowData">
              <el-form-item label="主要负责人：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
              <el-form-item label="联系电话：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
              <el-form-item label="负责人手机：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
            </div>
            <div class="rowData">
              <el-form-item label="特种作业人数：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
              <el-form-item label="驻场职工人数：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
              <el-form-item label="业务需求科室协调/管理人员：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
            </div>
            <div class="rowData">
              <el-form-item label="志愿（专职）消防人人数：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
              <el-form-item label="志愿（专职）消防队负责人：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
              <el-form-item label="消防重点部位数量：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
            </div>
            <div class="rowData">
              <el-form-item label="账号管理人员电话：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
              <el-form-item label="从业人员信息登记平台账号：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
              <el-form-item label="志愿（专职）消防队联系方式：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
            </div>
            <div class="rowData">
              <el-form-item label="账号管理人员：" class="inputStyle">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
            </div>
            <div style="margin: 20px 30px 0 30px;">
              <el-form-item label="危险物品及管控物品配备情况：" >
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
            </div>
            <div style="margin: 20px 30px 0 30px;">
              <el-form-item label="备注：">
                <el-input v-model="formData.contractPeriod"></el-input>
              </el-form-item>
            </div>
            <div class="rowData">
              <el-form-item label="附件：" class="inputStyle">
                <el-upload
                  multiple
                  action=""
                  v-model="formData.file"
                  class="fileUpload"
                >
                  <el-icon class="el-icon--upload" size="20"><upload-filled /></el-icon>
                  <div class="el-upload__text">
                    <em>点击上传</em>
                  </div>
                </el-upload>
              </el-form-item>
            </div>
          </el-form> -->
      <!-- </div> -->
<!--      <div class="line"></div>-->
      <div style="background-color: #fff;padding: 20px 10px;">
        <v-form-render :form-json="formJson" :form-data="formData" :option-data="optionData"  ref="vFormRef">
        </v-form-render>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { computed, ref, reactive, onBeforeMount, nextTick,onMounted } from "vue";
import { ElMessage } from 'element-plus'
import { getModelData} from '@/api/secure/securityTemplateManager'
import {listIdAndType} from '@/api/secure/catalogue'
// const formData = ref({
//   model: '',
//   unitName: '',
//   unitNumber: '',
//   roomNumber: '',
//   businessDesc: '',// 业务简述
//   contractPeriod: '',// 合同期限
//   principalPhone: '',
//   isSign: 0,// 是否签订安全协议
//   file: ''// 文件
// })

const emit = defineEmits(["getValue"]);

// const formJson = reactive({"widgetList":[{"key":114110,"type":"card","category":"container","icon":"card","widgetList":[],"options":{"name":"card30380","label":"card","hidden":false,"folded":false,"showFold":true,"cardWidth":"100%","shadow":"never","customClass":[]},"id":"card30380"},{"key":56024,"type":"time-range","icon":"time-range-field","formItemFlag":true,"options":{"name":"timerange92285","label":"time-range","labelAlign":"","defaultValue":null,"startPlaceholder":"","endPlaceholder":"","columnWidth":"200px","size":"","autoFullWidth":true,"labelWidth":null,"labelHidden":false,"readonly":false,"disabled":false,"hidden":false,"clearable":true,"editable":false,"format":"HH:mm:ss","required":false,"requiredHint":"","validation":"","validationHint":"","customClass":[],"labelIconClass":null,"labelIconPosition":"rear","labelTooltip":null,"onCreated":"","onMounted":"","onChange":"","onFocus":"","onBlur":"","onValidate":""},"id":"timerange92285"},{"key":95758,"type":"date-range","icon":"date-range-field","formItemFlag":true,"options":{"name":"daterange109611","label":"date-range","labelAlign":"","type":"daterange","defaultValue":null,"startPlaceholder":"","endPlaceholder":"","columnWidth":"200px","size":"","autoFullWidth":true,"labelWidth":null,"labelHidden":false,"readonly":false,"disabled":false,"hidden":false,"clearable":true,"editable":false,"format":"YYYY-MM-DD","valueFormat":"YYYY-MM-DD","required":false,"requiredHint":"","validation":"","validationHint":"","customClass":"","labelIconClass":null,"labelIconPosition":"rear","labelTooltip":null,"onCreated":"","onMounted":"","onChange":"","onFocus":"","onBlur":"","onValidate":""},"id":"daterange109611"}],"formConfig":{"modelName":"formData","refName":"vForm","rulesName":"rules","labelWidth":80,"labelPosition":"left","size":"","labelAlign":"label-left-align","cssCode":"","customClass":[],"functions":"","layoutType":"PC","jsonVersion":3,"onFormCreated":"","onFormMounted":"","onFormDataChange":""}})
const formJson = reactive({})
const formData = reactive({})
const optionData = reactive({})
const vFormRef = ref(null)
const modelName = ref(null)
const unitTypeList = ref([])
const unitType = ref(null)
const disabled = ref(true)

const props = defineProps<{
    modelId: string
  }>()

  onMounted(() => {
  if(props.modelId != null || props.modelId != undefined) {
    getModelData(props.modelId).then(res => {
      if(res.code === '1') {
        ElMessage.success(res.message)
        formJson.widgetList = JSON.parse(res.data.formJson).widgetList

        formJson.formConfig = JSON.parse(res.data.formJson).formConfig
        console.log(formJson)
        formJson.widgetList.forEach(element => {
          if(element.type == 'input') {
            element.options.readonly = true
          }else if(element.type == 'textarea') {
            element.type = 'input'
            element.options.readonly = true
          }else if(element.type == 'number') {
            element.type = 'input'
            element.options.readonly = true
          }else if(element.type == 'select') {
            element.type = 'input'
            element.options.readonly = true
            element.options.optionItems.forEach(e => {
              if(e.value = element.options.defaultValue) {
                element.options.defaultValue = e.label
              }
            })
          }else if(element.type == 'radio') {
            element.options.disabled = true
          }else if(element.type == 'rate') {
            element.options.disabled = true
          }else if(element.type == 'html-text') {
            element.options.disabled = true
          }else if(element.type == 'static-text') {
            element.options.disabled = true
          }else if(element.type == 'button' || element.type == 'button') {
            element.options.readonly = true
          }else {
            element.type = 'input'
            element.options.readonly = true
          }

          // element.options.disabled = true
        });
        modelName.value = res.data.modelName
        unitType.value = res.data.catalogueIdStr
        disabled.value = true
      }else {
        ElMessage.error(res.message)
      }
    })

    listIdAndType().then(res => {
      if(res.code === '1' && res.data) {
        unitTypeList.value = res.data;
        unitTypeList.value.forEach(e => {
          if(e.id === unitType.value) {
            console.log(123)
            unitType.value = e.catalogueName
          }
        })
      }
    })
  }
})

/**
 * 返回，回到index
 */
const back = () => {
  emit("getValue",false)
};

/**
 * 保存，回到index
 */
const save = () => {
  back()
};
const showForm = () => {
};
</script>

<style scoped>
  .common{
    padding: 40px 100px;
    height: 100%;
    margin: 20px;
    background-color: #fff;
  }
  .action{
    float: right;
    position: relative;
  }
  .line{
    border-top: 1px solid #1caad5;
    margin-top: 35px;
    margin-bottom: 10px;
  }
  .info{

  }
  .rowData{
    display: flex;
    margin-top: 20px;
  }
  .selectStyle{
    width: 300px;
  }
  .inputStyle{
    width: 450px;
    margin: 0 30px;
  }
  .fileUpload{
    width: 100px;
    height: 30px;
    border: 1px solid var(--el-border-color);
    border-radius: 5px;
    color: #5a5756;
    text-align: center;
  }

  :deep(.el-input__wrapper) {
    box-shadow: none;
  }
  :deep(.el-textarea__inner) {
    box-shadow: none;
  }
</style>
